package com.dotflat.training.controller;

import com.dotflat.training.po.ResTagPO;
import com.dotflat.training.service.XETApiService;
import com.tuo51.foudation.model.StatusResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.matt.foundation.constant.RequestConstant.TICKET;


/**
 * @author wangxuchuan
 * @date 2020/10/30
 */

@RestController
@Slf4j
@RequestMapping("/api/yz/course")
@Api(tags = "有赞教育 - 课程")
public class YZCourseController {

//    @Autowired
//    private YZTokenService yzTokenService;
//
//    @Autowired
//    private DefaultYZClient yzClient;

//    @Autowired
//    private XETApiService xetApiService;
//
//    @GetMapping("/course_groups")
//    @ApiOperation(value = "课程分组， 响应定义参见  https://doc.youzanyun.com/detail/API/0/656")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
//    })
//    public StatusResponse getGroupList(@RequestHeader(TICKET) String ticket,
//                                       @RequestParam(required = false, defaultValue = "0") int pageNum,
//                                       @RequestParam(required = false, defaultValue = "20") int pageSize
//    ) {
//
//        List<ResTagPO> result = new ArrayList<>();
//                //xetApiService.getResTagList(pageNum, pageSize);
//
//        return StatusResponse.success(result);
//    }
//
//    @GetMapping("/list")
//    @ApiOperation(value = "课程列表， 响应字段参见 https://doc.youzanyun.com/detail/API/0/657")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
//            @ApiImplicitParam(paramType = "formData", name = "groupId", value = "分组id", required = true, dataType = "integer"),
//            @ApiImplicitParam(paramType = "formData", name = "keyword", value = "关键字", required = false, dataType = "String")
//    })
//    public StatusResponse getCourseList(@RequestHeader(TICKET) String ticket,
//                                        @RequestParam(required = false, defaultValue = "0") int pageNum,
//                                        @RequestParam(required = false, defaultValue = "20") int pageSize,
//                                        @RequestParam(required = false) Long groupId,
//                                        @RequestParam(required = false) String keyword
//
//    ) {
//        return StatusResponse.success(new ArrayList<>());
////        if (groupId == null){
////            Map result = xetApiService.getGoodsList(pageNum, pageSize, keyword);
////            return StatusResponse.success(result);
////        }
////
////        Map result = xetApiService.getTagResourceList(pageNum, pageSize, groupId);
////        return StatusResponse.success(result);
//    }

    @Autowired
    private XETApiService xetApiService;

    @GetMapping("/course_groups")
    @ApiOperation(value = "课程分组， 响应定义参见  https://doc.youzanyun.com/detail/API/0/656")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
    })
    public StatusResponse getGroupList(@RequestHeader(TICKET) String ticket,
                                       @RequestParam(required = false, defaultValue = "0") int pageNum,
                                       @RequestParam(required = false, defaultValue = "20") int pageSize
    ) {

        List<ResTagPO> result = xetApiService.getResTagList(pageNum, pageSize);

        return StatusResponse.success(result);
    }

    @GetMapping("/list")
    @ApiOperation(value = "课程列表， 响应字段参见 https://doc.youzanyun.com/detail/API/0/657")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "formData", name = "groupId", value = "分组id", required = true, dataType = "integer"),
            @ApiImplicitParam(paramType = "formData", name = "keyword", value = "关键字", required = false, dataType = "String")
    })
    public StatusResponse getCourseList(@RequestHeader(TICKET) String ticket,
                                        @RequestParam(required = false, defaultValue = "0") int pageNum,
                                        @RequestParam(required = false, defaultValue = "20") int pageSize,
                                        @RequestParam(required = false) Long groupId,
                                        @RequestParam(required = false) String keyword

    ) {
//        return StatusResponse.success(new ArrayList<>());
//        if (groupId == null){
        Map result = xetApiService.getGoodsList(pageNum, pageSize, keyword);
        return StatusResponse.success(result);
//        }
//
//        Map result = xetApiService.getTagResourceList(pageNum, pageSize, groupId);
//        return StatusResponse.success(result);
    }
}
